<template>
  <rx-dialog @handOk="handOk" @cancel="cancel">
    <rx-layout>
      <div slot="header">
        <div class="table-page-search-wrapper">
          <a-form layout="inline">
            <a-row :gutter="48">
              <a-col :span="8">
                <a-form-item label="名称">
                  <a-input placeholder="请输入名称" v-model="queryParam.Q_NAME__S_LK"/>
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <a-form-item label="标识">
                  <a-input placeholder="请输入标识" v-model="queryParam.Q_KEY__S_LK"/>
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <span class="table-page-search-submitButtons">
                  <a-button type="primary" @click="loadData" icon="search">查询</a-button>
                  <span style="padding-left:5px;"><a-button @click="reset" >重置</a-button></span>
                </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
      </div>
      
      <div slot="center" style>
        <rx-grid
            ref="table"
            :allowRowSelect="true"
            :multiSelect="false"
            :columns="columns"
            :defaultPageSize="10"
            url="/api-form/form/codegen/formCodegenFileTemplate/query"
            :queryParam="queryParam"
            data-field="result.data"
            :pageSizeOptions="['10','30','40']"
            id-field="id"
            @selectChange="onSelectChange"
        >
          <span slot="enabled" slot-scope="{text,record,index}" >
            <a-tag :color="enabledMap[text].color">
              <span>{{enabledMap[text].text}}</span>
            </a-tag>
          </span>
        </rx-grid>
      </div>
    </rx-layout>
  </rx-dialog>
</template>

<script>
  import {BaseList, RxLayout, Util} from "@lowcode/jpaas-common-lib"

  export default {
    name: 'SysAuthSettingDialog',
    mixins: [BaseList],
    components: {
      RxLayout
    },
    props: {
      layerid: {
        type: String,
        default: ""
      },
      destroy: {
        type: Function
      }
    },
    data() {
      return {
        columns: [
          {
            title: '序号',
            type: 'indexColumn',
            width: 100,
            dataIndex: 'serial',
            scopedSlots: {customRender: 'serial'}
          },
          {title: '名称', dataIndex: 'name', width: 100},
          {title: '标识', dataIndex: 'key', width: 100},
          {title: '是否启用', dataIndex: 'enabled', width: 100, scopedSlots: {customRender: 'enabled'}}
        ],
        enabledMap: {
          'YES': {color: 'green', text: '启用'},
          'NO': {color: 'blue', text: '禁用'}
        },
      }

    },
    created() {
      this.queryParam.Q_ENABLED__S_EQ="YES";
    },
    methods: {
      i18n(name,text,key){
        return this.$ti18(name,text,"formCodegenFileTemplate",key);
      },
      reset(){
        this.$nextTick(() => {
          this.queryParam = {Q_ENABLED__S_EQ:"YES"};
          this.$nextTick(() => {
            this.$refs[this.table].loadData();
          })
        })
      },
      cancel(){
        Util.closeWindow(this,"cancel");
      },
      handOk(vm) {
        var row=this.$refs.table.getSelectedRow();
        if(!row){
          this.$message.warning("请选择一行记录!");
          vm.loading=false;
          return;
        }
        Util.closeWindow(this, "ok",row);
      }
    }
  }
</script>
<style scoped>

</style>

